package cn.edu.ecut.scheduling;

public class YieldThread extends Thread {
	
	public YieldThread( String name , int priority ) {
		super(name);
		this.setPriority( priority );
	}

	@Override
	public void run() {
		for( int i = 100 ; i < 106 ; i++ ) {
			System.out.println( Thread.currentThread() + " : " + i );
			Thread.yield(); // 线程让位: 让位给与自己具有同等优先级 以及 优先级比自己高的线程，但是自己还是要去竞争CPU
		}
	}
	
	
	public static void main(String[] args) {
		
		Thread f = new YieldThread( "first" , Thread.NORM_PRIORITY + 1 );
		Thread s = new YieldThread( "second" , Thread.NORM_PRIORITY - 1 );
		Thread t = new YieldThread( "third" , Thread.MIN_PRIORITY );
		
		t.start();
		s.start();
		f.start();
		
	}
	
	
}
